package com.geh.learn.collections;

import com.google.common.collect.Sets;

import java.util.Set;

public class HashSetTest {

    public static void main(String[] args) {

        Set<TestObj> t1 = Sets.newHashSet();
        TestObj to1 = new TestObj("1");
        TestObj to2 = new TestObj("2");
        t1.add(to1);
        t1.add(to2);
        System.out.println("to1 : " + to1.hashCode());
        System.out.println("to2 : " + to2.hashCode());
        System.out.println("t1 = [" + t1 + "]");
    }

}

class TestObj {
    private String a;

    public String getA() {
        return a;
    }

    public void setA(String a) {
        this.a = a;
    }

    public TestObj(String a) {
        this.a = a;
    }

    @Override
    public boolean equals(Object o) {
        return this.hashCode() == o.hashCode();
    }

    @Override
    public int hashCode() {
        return 1;
    }

    @Override
    public String toString() {
        return "TestObj{" +
                "a='" + a + '\'' +
                '}';
    }
}
